import { createSlice } from "@reduxjs/toolkit"
import { User } from "../Types/Api/user"

type State = {
  isLogin: boolean
  userInfo: User
}
export const userSlice = createSlice({
  name: "user",
  initialState: {
    isLogin: false,
    userInfo: {},
  } as State,
  reducers: {
    changeLoginState(state, action) {
      state.isLogin = action.payload
    },
    initUser(state, action) {
      state.userInfo = action.payload
    },
    clearUser(state) {
      state.userInfo = {} as User
    },
  },
})

export const userReducer = userSlice.reducer
export const { changeLoginState, initUser, clearUser } = userSlice.actions
